package com.taiyuan.zfmvp.sharding.service.impl;

import com.taiyuan.zfmvp.sharding.dao.TestCodeMapper;
import com.taiyuan.zfmvp.sharding.dao.TestShardingMapper;
import com.taiyuan.zfmvp.sharding.model.TestCode;
import com.taiyuan.zfmvp.sharding.model.TestSharding;
import com.taiyuan.zfmvp.sharding.service.TestShardingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @param
 * @Author: zhoufang@si-tech.com.cn
 * @Descriiption:
 * @Date 2022/1/30
 * @return
 */
@Service
public class TestShardingServiceImpl implements TestShardingService {


    private static final Logger logger = LoggerFactory.getLogger(TestShardingServiceImpl.class.getName());


    @Resource
    private TestShardingMapper testShardingMapper;

    @Resource
    private TestCodeMapper testCodeMapper;

    /**
     * @param testSharding
     * @Author zhoufang@si-tech.com.cn
     * @Description 添加信息
     * @Date 2022/1/30
     * @Param
     * @Return
     */
    @Override
    public void addShardingInfo(TestSharding testSharding) {
        testShardingMapper.insertSelective(testSharding);
    }

    @Override
    public void addCode(TestCode testCode) {
        testCodeMapper.insertSelective(testCode);
    }

    @Override
    public TestCode getTestCode(int id) {
        return testCodeMapper.selectByPrimaryKey(id);
    }

    @Override
    public void addShardingInfo() {

        long start = System.currentTimeMillis();

        for (int i = 0; i < 10000; i++) {
            TestSharding testSharding = new TestSharding();
            testSharding.setPhoneNo(i+"0");
            testSharding.setCouponCode(i+"");
            testSharding.setSex(i%2);
            testShardingMapper.insertSelective(testSharding);
        }

        long end = System.currentTimeMillis();
        logger.info("执行批量插入 =======END，耗时=" + (end-start));
    }
}
